package com.jio.controller;

import com.jio.pojo.UserRole;
import mapper.UserMapper;
import com.jio.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.util.List;

public class UserTest {
    public static void main(String[] args) throws IOException {
        SqlSessionFactory factory = new SqlSessionFactoryBuilder()
                .build(Resources.getResourceAsStream("mybatis-config.xml"));
        //2、创建SqlSession对象
        SqlSession session = factory.openSession();
        //3、调用session的方法namespace的名字.id
        //List<User> users = session.selectList("mapper.UserMapper.selectAllUser");
        //以上这种调用方式是基础的使用方式 需要单独学习mybatisAPI

        //让mybatis基于对应的配置文件 创建接口的实现类
        UserMapper mapper = session.getMapper(UserMapper.class);
        List<UserRole> users = mapper.getUserList();

        //4、打印测试
        for(UserRole u:users){
            System.out.println(u);
        }
        //5、关闭资源
        session.close();


    }
}
